package com.wyl.wyl.testapplication.utils;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.WindowManager;
import android.widget.ListView;


import com.wyl.wyl.testapplication.R;
import com.wyl.wyl.testapplication.base.BaseDialog;
import com.wyl.wyl.testapplication.adapter.LocationListAdapter;
import com.wyl.wyl.testapplication.bean.CarMainBean;

import java.util.List;

/**
 * ----------
 * Author: Leo
 * Date: 2019/4/25
 * Email: 18304097708@163.com
 * Description:
 * ----------
 */

public class DialogUtil {

    public static abstract class LocationListener {
        public abstract void onSelect(Dialog dialog, String code, String name, String id);
    }

    public static Dialog getLocationDialog(final Context context, final List<CarMainBean.BodyBean.WhListBean> list,
                                           final LocationListener listener) {
        BaseDialog baseDialog = BaseDialog.createDialog(context, R.layout.dialog_dispose_way,
                null, WindowManager.LayoutParams.WRAP_CONTENT, (Context con, View view, Dialog
                        dialog) -> {
                    ListView disposeWayList = (ListView) view.findViewById(R.id.disposeWayList);
                    LocationListAdapter adapter = new LocationListAdapter(context, list, new LocationListAdapter.LocationListAdapterListener() {
                        @Override
                        public void onSelect(String code, String name, String id) {
                            dialog.cancel();
                            listener.onSelect(dialog, code, name, id);
                        }
                    });
                    disposeWayList.setAdapter(adapter);
                }
        );
        return baseDialog;
    }
}
